package com.txl.cn.spark01

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
  * Created by txl on 2017/12/25.
  */
object SparkDemo {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    val sc = new SparkContext(conf)
    val lines = sc.textFile(args(0))
    val words: RDD[String] = lines.flatMap(_.split(" "))
    val wordAndOne: RDD[(String, Int)] = words.map((_,1))
    val reduced = wordAndOne.reduceByKey(_+_)
    val res = reduced.sortBy(- _._2)
    res.saveAsTextFile(args(1))
  }
}
